package sm;
import java.util.Hashtable;

public class ServiceRegistry {
	 private static ServiceRegistry ref;
	 public static Hashtable serviceIds = new Hashtable(); // when testing is done make private
     
	 private ServiceRegistry(){
	    }
	 public static synchronized ServiceRegistry getInstance(){
		 if (ref == null)
	            ref = new ServiceRegistry();
		 return ref;
	    }
	 public synchronized void registerService(String key,int eventId){
		 addService(key,eventId);

	    }
	 private static synchronized void addService(String key,int eventId){
		 if(idNotRegistered(key)){
			 serviceIds.put(key, new Integer(eventId));
	        }//importante de ver: se puede crear un objeto y meterlo en un hastable sin una variable
           // que lo refencie como aqui Integer, no se como se llama pero no importa con la key puedo
           //sacarlo nuevamente y con sus metodos extraigo la info qeu tiene adentro, el nombre del
           // objeto es irrelevante.
	    }
	 public static synchronized void removeService(String key){// this method should not be used
		 // alone, because each sensing event keeps a non NULL ref that will not allow the 
		 // re registration of a service after a key has been removed. so the system thinks the
		 // event is not available if the registry does not have it.
		 serviceIds.remove(key);
	    }
	 public static synchronized boolean isServiceRegistered(String key){
		 return serviceIds.containsKey(key);
	    }
	 private static synchronized boolean idNotRegistered(String key){
		 return !serviceIds.containsKey(key);
	    }
	 public static synchronized int getSizeServiceIds(){
		 return serviceIds.size();
	 }


	

}
